package com.yanq.liancar.fragment;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.RelativeLayout;

import com.flyco.tablayout.SlidingTabLayout;
import com.gyf.barlibrary.ImmersionBar;
import com.yanq.liancar.R;
import com.yanq.liancar.base.BaseLazyFragment;

import java.util.ArrayList;

import butterknife.BindView;

/**
 * A simple {@link Fragment} subclass.
 */
public class CFindFragment extends BaseLazyFragment {
    private ArrayList<Fragment> mFragments = new ArrayList<>();
    private final String[] mTitles = {
            "精选", "经济", "金融"
            , "互联网", "美妆", "生活"
    };
    private MyPagerAdapter mAdapter;

    @BindView(R.id.ll_top)
    RelativeLayout toolbar;
    @BindView(R.id.tab_layout)
    SlidingTabLayout mTabLayout;
    @BindView(R.id.viewpage)
    ViewPager mViewPager;

    @Override
    protected int setLayoutId() {
        return R.layout.fragment_cfind;
    }
    
    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initViews();
        for (int i = 0; i < mTitles.length; i++) {
            mFragments.add(SimpleCardFragment.getInstance(i));
        }
        mAdapter = new MyPagerAdapter(getChildFragmentManager());
        mViewPager.setOffscreenPageLimit(6);
        mViewPager.setAdapter(mAdapter);
        mTabLayout.setViewPager(mViewPager);

    }

    private void initViews() {
        ImmersionBar.setTitleBar(getActivity(), toolbar);
    }
    @Override
    protected void initImmersionBar() {
        super.initImmersionBar();
//        mImmersionBar.statusBarDarkFont(true)
//                .init();
    }

    private class MyPagerAdapter extends FragmentPagerAdapter {
        public MyPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public int getCount() {
            return mFragments.size();
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return mTitles[position];
        }

        @Override
        public Fragment getItem(int position) {
            return mFragments.get(position);
        }
    }

}
